<%@ page contentType="text/html;charset=UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="tags" tagdir="/WEB-INF/tags" %>
<c:set var="ctx" value="${pageContext.request.contextPath}" />

<!DOCTYPE html>
<head>
<title>_盘点周期设置</title>
<script type="text/javascript">
	$(function() {
		$("#queryForm").validate(); 
		$("#dataForm").validate(); 
	});
	function save(custCode,wareHouseCode){
		if($("#dataForm").valid()){
			$.ajax({
				type : 'post',
				url : '${ctx}/v2/checkPlanSetting/saveCheckPlanSetting',
				data : {
					id : $("#id_"+custCode+"_"+wareHouseCode).val() == 0 ? null : $("#id_"+custCode+"_"+wareHouseCode).val(),
					customerCode : custCode,
					warehouseCode : wareHouseCode,
					day : $("#day_"+custCode+"_"+wareHouseCode).val()
					},
				dataType : 'json',
				success : function(data) {
					$("#id_"+custCode+"_"+wareHouseCode).val(data.id);
					showMessage(custCode+"_"+wareHouseCode);
				},
				error : function() {
					alert("操作数据错误！");
				}
			});
		}
	}
	function showMessage(id) {
		$("#img_"+id).show('fast',function(){
			$(this).hide(2000);
		});
	}
</script>
</head>
<body>
<section class="content">
	<div class="row">
		<div class="col-md-12">

			<!-- Primary box -->
			<div class="box box-solid box-primary">
				<div class="box-header">
					<i class="fa fa-search"></i>
					<h3 class="box-title">搜索栏</h3>
					<div class="box-tools pull-right">
						<button class="btn btn-primary btn-sm" data-widget="collapse">
							<i class="fa fa-minus"></i>
						</button>
					</div>
				</div>
				<div class="box-body">
				<form class="form-search" id="queryForm" action="${ctx}/v2/checkPlanSetting/queryCheckPlanSetting" method="post">
					<div class="form-group row">
						<div class="col-sm-3">
							<div class="input-group col-sm-12">
								<span class="input-group-text"> 商家名称： </span> 
								<select class="form-control required" id="customerCode" name="customerCode">
									<option value=""></option>
									<c:forEach items="${customerList}" var="customer">
										<option value="${customer.customerCode}"
											<c:if test="${param.customerCode eq customer.customerCode}">selected=selected</c:if>>${customer.customerName}</option>
									</c:forEach>
								</select>
								
							</div>
						</div>
						<div class="col-sm-9"><button class="btn btn-info" type="submit">搜索</button></div>
					</div>
				</form>
				</div>

			</div>
			<!-- /.box-body -->

		</div>
		<!-- /.col -->
	</div>
	<!-- /.row -->

	<div class="form-group row">
		<div class="col-md-12">
			<div class="box box-primary">
				<div class="box-header"></div>
				<div class="box-body">
					<form id="dataForm">
					<table id="contentTable"
						class="table table-striped table-bordered table-condensed">
						<thead>
							<tr>
								<th>商家</th>
								<th>仓库</th>
								<th>盘点周期(每月的几号)</th>
								<th>操作</th>
							</tr>
						</thead>
						<tbody>
						<c:forEach items="${data}" var="data">
							<tr id="tr_${data.id}">
								<td><c:forEach items="${customerList}" var="customer">
										<c:if test="${data.customerCode eq customer.customerCode }">${customer.customerName}</c:if>
									</c:forEach>
								</td>
								<td><c:forEach items="${warehouseList}" var="warehouse">
										<c:if test="${data.warehouseCode eq warehouse.groupCode }">${warehouse.groupName}</c:if>
									</c:forEach>
								</td>
								<td>
								<input type="hidden" id="id_${data.customerCode}_${data.warehouseCode}" value="${data.id}"></input>
								<input type="text" value="${data.day }" max="28" min="1" id="day_${data.customerCode}_${data.warehouseCode}" class="form-control pull-right required" name="day_${data.customerCode}_${data.warehouseCode}"/></td>
								<td>
									<button class="btn btn-primary" onclick="save('${data.customerCode}','${data.warehouseCode}')" type="button">保存</button>
									<img id="img_${data.customerCode}_${data.warehouseCode}" src="${ctx}/static/images/checkSmall.gif" class="img-circle" alt="success" hidden="true"/>
								</td>
							</tr>
						</c:forEach>
						</tbody>
					</table>
					</form>
				</div>
			</div>
			<!-- /.box -->
		</div>
		<!-- /.col -->
	</div>
	<!-- /.row -->
</section>
</body>
</html>